{% extends "survey/base.html" %}
{% load i18n %}
{% load survey %}
{% block scripts %}{% load adminmedia %}
<style type="text/css">
.question pre { margin-left: 2em; }
.question .bar { margin-left: 2em; }
.question .barAnswer { font-weight: bold; width: 100% !important; text-align: left;}
.question .answer { margin-left: 2em; }
.question .question-results .barColor {
    background-color: #7ca0c7;
    background-image: url({% admin_media_prefix %}img/admin/default-bg.gif);
    background-repeat: repeat-x;
    background-attachment: scroll;
    padding: 0px;
    background-x-position: left;
    background-y-position: top;
}
</style>
{% endblock %}
{% block content %}
<h1>{{ title }} <i>({{ survey.interview_count }} {% trans "Interview" %}{{ survey.interview_count|pluralize:"s" }})</i></h1>
<br/>
{% regroup answers.all|dictsort:"question.order" by question as question_list %}
{% for q in question_list %}
<div class='question'>
    <h2 onmouseout='this.style.backgroundColor="#FFF";'
            onmouseover='this.style.backgroundColor="#ECECEC";'
            onclick='var foo=document.getElementById("results{{forloop.counter}}");
                     if (foo.style.display=="none") { foo.style.display="block"; }
                     else { foo.style.display="none"; }'
        >{{ q.grouper.text }} <i>({{ q.grouper|answer_count:survey }} {% if q.grouper.choices.count %}{% trans "Vote" %}{% else %}{% trans "Answer" %}{% endif %}{{ q.grouper|answer_count:survey|pluralize:"s" }})</i></h2>
    <div id='results{{forloop.counter}}' class='question-results'>
    {% if q.grouper.choice_group.choices.count %}
        {% for choice in q.grouper.choice_group.choices.all|dictsort:"order" %}
            <table border="0" cellpadding="0" cellspacing="0" class="bar">
                <caption class="barAnswer">{% ifequal question.qtype "I" %}<img src="{{ choice.text }}"/>{% else %}{{ choice.text }}{% endifequal %}</caption>
                <tr>
                    <td style="width: {% widthratio choice.count question.answer_count 100 %}%" class="barColor">{% if choice.count %}&nbsp;{% endif %}</td>
                    <td class="barPercent"><strong class="barVotes">{{q.grouper|answers:survey|choice_count:choice}}&nbsp;{% trans "vote" %}{{ q.grouper|answers:survey|choice_count:choice|pluralize:"s" }}</strong>&nbsp;/&nbsp;{% widthratio q.grouper|answers:survey|choice_count:choice q.grouper|answer_count:survey 100 %}%</td>
                </tr>
            </table>
        {% endfor %}
    {% else %}    
        {% for a in q.list|dictsort:"pk" %}
                <div>{% if view_submissions %}<a href='{% url answers-detail survey_slug=survey.slug,key=answer.session_key %}/'>{% endif %}{% trans "Answer" %} {{ forloop.counter }}{% if view_submissions %}</a>{% endif %} {% trans "of" %} {{ q.grouper|answer_count:survey }}</div>
                {{ a.text }}
                <hr/>
            {% endfor %}
    {% endif %}
    </div>
</div>
{% endfor %}
{% endblock %}
